package design.proxy.copycglib;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class HealthyKidMethodInterceptor implements IMethodInterceptor {
    @Override
    public Object intercept(Object proxy, Method method, Object[] args,
            Method proxyMethod) {
        Kid kid = (Kid) proxy;
        if("eat".equals(method.getName())) {
            kid.washHand();
        }
        Object result = null;
        try {
            result = proxyMethod.invoke(proxy, args);
        } catch (IllegalAccessException | IllegalArgumentException
                | InvocationTargetException e) {
            e.printStackTrace();
        }
        if("eat".equals(method.getName())) {
            kid.brushTeeth();
        }
        return result;
    }
}
